﻿using Microsoft.Build.BuildEngine;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Reflection;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Spire;
using Spire.Pdf;
using Spire.Pdf.HtmlConverter.Qt;
using System.Drawing;
using Spire.Pdf.Graphics;
using Spire.Pdf.HtmlConverter;
using System.Linq.Dynamic;
using AutoMapper;
using RabbitMQ.Client;

namespace ConsoleApp1
{
    class Program
    {
        static string content = "";
        static void Main(string[] args) {
            while (true) {
                Console.WriteLine("输入消息内容:");
                string content = Console.ReadLine();
                if (content == "exit")
                    break;

                var factory = new ConnectionFactory();
                factory.HostName = "10.10.10.45";//RabbitMQ服务在本地运行
                factory.UserName = "root";//用户名
                factory.Password = "123123";//密码

                using (var connection = factory.CreateConnection()) {
                    using (var channel = connection.CreateModel()) {
                        channel.QueueDeclare("hello", false, false, false, null);//创建一个名称为hello的消息队列
                        string message = content; //传递的消息内容
                        var body = Encoding.UTF8.GetBytes(message);
                        channel.BasicPublish("", "hello", null, body); //开始传递
                        Console.WriteLine("已发送： {0}", message);
                    }
                }

            }
        }

        //Student s1 = new Student {
        //    className = "1年级1班", user = new TestUser {
        //        id = Guid.NewGuid(),
        //        age = 18,
        //        name = "laowang"
        //    }
        //};

        //Student s2 = new Student {
        //    className = "2年级2班", user = new TestUser {
        //        id = Guid.NewGuid(),
        //        age = 20,
        //        name = "laowang"
        //    }
        //};

        //Student s3 = new Student {
        //    className = "2年级2班", user = new TestUser {
        //        id = Guid.NewGuid(),
        //        age = 18,
        //        name = "zhangsan"
        //    }
        //};

        //Student s4 = new Student {
        //    className = "2年级2班", user = new TestUser {
        //        id = Guid.NewGuid(),
        //        age = 20,
        //        name = "zhangsan"
        //    }
        //};

        //var a = new[] { s1, s2, s3, s4 };

        //a.OrderBy("User.age asc,User.name asc").ToList().ForEach(r => {
        //    Console.WriteLine(JsonConvert.SerializeObject(r));
        //});
        //Console.ForegroundColor = ConsoleColor.Red;
        //a.OrderBy(r => r.user.age).ThenBy(r => r.user.name).ToList().ForEach(r => {
        //    Console.WriteLine(JsonConvert.SerializeObject(r));
        //});

        //Mapper.Initialize(r => {
        //    r.CreateMap<TestUser, TestUserDto>();
        //    r.CreateMap<Student, StudentDto>();
        //});


        //Student s1 = new Student {
        //    className = "1年级1班",
        //    user = new TestUser {
        //        id = Guid.NewGuid(),
        //        age = 18,
        //        name = "laowang"
        //    }
        //};

        //var result = Mapper.Map<StudentDto>(s1);

        //Console.WriteLine(JsonConvert.SerializeObject(result));
    }

    public class StudentDto
    {
        public TestUserDto user { get; set; }

        public string user_name { get; set; }
    }

    public class TestUserDto
    {
        public string name { get; set; }
        public int age { get; set; }
    }

    public class TestUser
    {
        public Guid id { get; set; }

        public string name { get; set; }

        public int age { get; set; }
    }

    public class Student
    {
        public string className { get; set; }

        public TestUser user { get; set; }
    }


}
